﻿package webCode {
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.events.*;
	
	public class webNode extends Sprite{
		
		var radius:Number;
		var color:Number;
		var thickness:Number;
		var connections:Array;
		var vx:Number;
		var vy:Number;
		var canMove:Boolean = true;
		var beingDragged:Boolean = false;
		var redNode:Boolean;
		var childrenNodes:Array;

		public function webNode(radius:Number=10, thickness:Number=1, color:uint=0x40FF00) {
			x = 0;
			y = 0;
			this.radius = radius;
			this.color = color;
			this.thickness = thickness;
			connections = new Array();
			childrenNodes = new Array();
			vx = 0;
			vy = 0;
		}
		
		public function updateConnections():void
		{
			for each(var c:Spring in connections)
			{
				if (beingDragged == false)
				{
					c.springTo();
				}
			}
		}
		
		public function setToRed()
		{
			redNode = true;
		}
		
		public function setToGreen()
		{
			redNode = false;
		}
		
		public function setStatic(b:Boolean):void
		{
			canMove = b;
		}
		
		public function render():void
		{
			if (redNode)
			{
				graphics.beginFill(0xFF0000)
				graphics.lineStyle(thickness, 0xFF0000);
			}
			else 
			{
				graphics.beginFill(color); 
				graphics.lineStyle(thickness, color);
			}
			graphics.drawCircle(0, 0, radius);
			graphics.endFill();
			//trace("node drawn at "+ x+ ","+ y);
		}

	}
	
}
